package be.pluyckx.batteryprogress.data.history.snapshot;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import be.pluyckx.batteryprogress.database.BatteryLevelFileStorage;
import be.pluyckx.batteryprogress.utils.StringUtils;

/**
 * Created by Philip on 28/08/13.
 */
public class ServiceItem implements BatteryLevelFileStorage.FileWritable {
  private String mServiceName;
  private int mPid;

  public ServiceItem(int pid, String serviceName) {
    mPid = pid;
    mServiceName = serviceName;
  }

  public String getServiceName() {
    return mServiceName;
  }

  public int getPid() {
    return mPid;
  }

  @Override
  public int streamSize() {
    return StringUtils.lengthUTF(mServiceName, true) + Integer.SIZE / 8;
  }

  @Override
  public void write(DataOutputStream dos) throws IOException {
    dos.writeInt(mPid);
    dos.writeUTF(mServiceName);
  }

  public ServiceItem(DataInputStream dis) throws IOException {
    mPid = dis.readInt();
    mServiceName = dis.readUTF();
  }
}
